package com.eclink.asset.setup.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eclink.asset.setup.convert.OrganizationConvert;
import com.eclink.asset.setup.domain.dao.Company;
import com.eclink.asset.setup.service.CompanyService;
import com.eclink.asset.setup.service.DeptService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysDept;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司Controller
 * 
 * @author chenshixian
 * @date 2024-09-18
 */
@Api("部门管理接口")
@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController {

    @Resource
    private CompanyService companyService;

    @Resource
    private DeptService service;

    @Resource
    private OrganizationConvert convert;

    @ApiOperation("查询")
    @PostMapping("/list")
    public ResponseEntity<List<SysDept>> list(Long companyId) {
        List<SysDept> list = service.selectDeptListByCompanyId(companyId);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("获取详细信息")
    @GetMapping(value = "/{id}")
    public ResponseEntity<SysDept> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectDeptById(id));
    }

    @ApiOperation("新增")
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody SysDept query) {
        return ResponseEntity.ok(service.insertDept(query));
    }

    @ApiOperation("修改")
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody SysDept query) {
        return ResponseEntity.ok(service.updateDept(query));
    }

    @ApiOperation("删除")
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        service.deleteDeptByIds(ids);
        return ResponseEntity.ok(1);
    }



}
